<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

 if(!isset($_GET["route"])){
  header("Location: Web/index.php");
}  else {
  $route = limpiarUrl($_GET["route"]);
  $secure = getIsSecureConnection();
  $url = $secure?'https://':'http://';
  $localHost = $_SERVER['HTTP_HOST'];
  $header = "Location: $url$localHost/Workflow/Web/index.php?page=FrmLoginWf&a=$route";
  header($header);
}

function limpiarUrl($route){
  if(strpos("/", $route) != -1){
    $arr = explode("/", $route);
    if(count($arr) > 1){
		return encriptar(array("empresa" => $arr[0], "url" => $arr[1]));
	}else{
		return encriptar(array("empresa" => $arr[0]));
	}
  }else{
    return encriptar(array("empresa" => $route));
  }
}

function encriptar($arr){
  return base64_encode(json_encode($arr));
}

function desencriptar($argumento, $key = null){
  $arr = json_decode(base64_decode($argumento));
  if(is_null($key)) return $arr;
  return $arr->$key;
}

function getIsSecureConnection(){
  return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'],'off');
}


?>
